---CSharp调用lua数据，lua数据手动维护
CSharpModel = {};
local this = CSharpModel;
require "Battle/Editor/SkillRoleMgr"

---背包满
CSharpModel.packetSizeMax = false

--[[
---背包满捡起物品时
function CSharpModel.DropItem()
    UIBottom.bagEffect()
end
---发送坐标进入副本
function CSharpModel.EnterFB(point)
    if InstanceManager.bossMap then
        return
    end

    local point = point:ToTable();
    local maptype = UIBattle.GetMapType();
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);

    local pt = string_split(point[1],",");
    local nextmapname = mapHandler.getNextMapName(pt);

    if(maptype > 2 and maptype ~= 2 and maptype ~= 4 and maptype ~= 6) then
        local leftEnemy = InstanceManager.GetLeftEnemyNum();
        if(leftEnemy > 0) then
            pop.Init("64",function(b)
            end,nextmapname,leftEnemy);
            return;
        end
    end

    --print("点击开始。。。。。");
    --print("nextmapname=" .. nextmapname);
    pop.Init("63",function(b)
        if b then
            InstanceManager.TryEntry(point[1]);
        end
    end,nextmapname);

end

---点击NPC
function CSharpModel.ClickNPC(obj)
    InstanceManager.OpenNPC(obj)
end

function CSharpModel.ClickRoundMonster()
    InstanceManager.enterRoundFight();
end

---entryMap消息之后，加载地图完成时回调
function CSharpModel.LoadMapFinish()
   -- InstanceManager.EntryMap2()
end

function CSharpModel.checkCanInteract(interType)

    interType = interType:ToTable();
    local mapinfo = G.serverData["mapInfo"];
    if(mapinfo == nil) then
        return false;
    end
    local mapitem = G.serverData["mapInfo"].itemList;
    for i=1,#mapitem,1 do

        if(mapitem[i].canAction == 1) then
            if mapitem[i].itemx == interType[1] and mapitem[i].itemy == interType[2] then
                return true;
            end
        end
    end
    return false;
end

function CSharpModel.getCanTakeItemName(itempos)

    itempos = itempos:ToTable();

    if G.serverData["mapInfo"] ~= nil then

        local mapitem = G.serverData["mapInfo"].itemList;
        for i=1,#mapitem,1 do

            if(mapitem[i].canAction == 1 and mapitem[i].itemx == itempos[1] and mapitem[i].itemy == itempos[2]) then
                return mapitem[i].itemAction;
            end
        end

    end

    return "";
end
function CSharpModel.isBagFull()
    local itemList = G.serverData["itemInfo"]["itemList"];

    if #itemList >= G.serverData["itemInfo"].packetSize then
        UISysTips.AddMsg(G.dataTable["MessageTips"]["Message"]["Task_BagFull"]);
    end
    return #itemList >= G.serverData["itemInfo"].packetSize;
end
function CSharpModel.picItemUp(itempos)

    itempos = itempos:ToTable();
    local itemindex = 0;
    if G.serverData["mapInfo"] ~= nil then

        local mapitem = G.serverData["mapInfo"].itemList;
        for i=1,#mapitem,1 do

            if(mapitem[i].canAction == 1 and mapitem[i].itemx == itempos[1] and  mapitem[i].itemy == itempos[2]) then
                SendMsg.Send(Config.msg_type.send_picUpMapItem,itempos[1],itempos[2]);
                itemindex = i;
                break;
            end
        end
    end

    local name = getProtocol(Config.msg_main_type.main_mapInfo,Config.sub_type_mapInfo.sub_picupItem);
    ListenEvent(name,function(data)

        CloseEvent(name);
        if(data["opt"] == 0) then
            if G.serverData["mapInfo"] ~= nil then
                local mapitem = G.serverData["mapInfo"].itemList;
                if mapitem[itemindex] ~= nil then
                    UISysTips.AddMsg("获得"..mapitem[itemindex].itemName);
                    if(data["disappear"] == 1) then
                        table.remove(mapitem,itemindex);
                    else
                        mapitem[itemindex].canAction = data["canAction"];
                    end
                end
            end
        end

    end);
end
]]
function CSharpModel.Get()
    return CSharpModel
end

function CSharpModel.GetUILock()
    local result = {}
    ---
    local tab = {}
    table.insert(tab,"UIStory")
    table.insert(tab,"UITaskComplete")
    table.insert(result,tab)
    ---
    tab = {}
    table.insert(tab,"UIRoundBattle")
    table.insert(tab,"UITaskComplete")
    table.insert(result,tab)
    ---
	 tab = {}
    table.insert(tab,"UIRoundBattle")
    table.insert(result,tab)
	---
	tab = {}
    table.insert(tab,"UITaskComplete")
    table.insert(result,tab)
	
	tab = {}
    table.insert(tab,"UIStory")
    table.insert(result,tab)
	
	tab = {}
    table.insert(tab,"UITaskComplete")
    table.insert(result,tab)

	---
    local json = require 'cjson'
    local result = json.encode(result);
    return result
end

function CSharpModel.initSkillRoleMgr()
    return SkillRoleMgr.init();
end

function CSharpModel.addLeftPlayer(modelId,pos)
    return SkillRoleMgr.addLeftPlayer(modelId,pos);
end

function CSharpModel.addRightPlayer(modelId,pos)
    return SkillRoleMgr.addRightPlayer(modelId,pos);
end

function CSharpModel.playSkill(skillid,skillData,shkillShow)
    SkillRoleMgr.playSkill(skillid,skillData,shkillShow);
end

function CSharpModel.playSkills(leftModels)
    SkillRoleMgr.playSkills(leftModels);
end

function CSharpModel.addBuff(buffid,leftroleobj,rightroleobj)
    SkillRoleMgr.addBuff(buffid,leftroleobj,rightroleobj);
end

function CSharpModel.stopplaySkill()
    SkillRoleMgr.stopplaySkill();
end

function CSharpModel.playReport(filepath,savePath)
    SkillRoleMgr.playReport(filepath,savePath);
end


function CSharpModel.DisConnectGameSvr()
	if not UIHeadInfo.reLogin then
		UISysTips.AddMsg("无网络信号");
        Game.coroutineReconnect();
	end
end

function CSharpModel.GetLanguageByKey(key)
    key = key[0] or ""
	return getLanguage(key)
end

function CSharpModel.OutFromTaptap()
    --local farBG = GameObject.Find("Stage/GRoot/UICity/FarBG")
    --if UICity then
    --    local mapMoveContent = UICity.MapMoveContent
    --    local nowCityArea = UICity.NowCityArea
    --    if farBG and mapMoveContent and nowCityArea then
    --        Util.Lua_SetLocalPositionXYZ(farBG.transform, mapMoveContent[nowCityArea], -105, 0)
    --    end
    --end
end

function CSharpModel.GetHeroNamesByTeam(teamIdx)
    return  SkillRoleMgr.getAllEntityName(teamIdx)
end
function CSharpModel.GetEntityAttribute(teamIdx,heroIdx)
    return  SkillRoleMgr.getEntityAttribute(teamIdx,heroIdx)
end
function CSharpModel.SetBattleInfo(is)
    SkillRoleMgr.setBattleInfo(is);
end
function CSharpModel.SetSaveReport(is)
    SkillRoleMgr.setSaveReport(is)
end
function CSharpModel.GetEntityFightInfoStr(teamIdx,heroIdx)
   return SkillRoleMgr.getEntityFightInfoStr(teamIdx,heroIdx)
end

function CSharpModel.GetEntityFightInfoStr(teamIdx,heroIdx)
    return SkillRoleMgr.getEntityFightInfoStr(teamIdx,heroIdx)
end
function CSharpModel.SetHeroTeamInfo(info)
    ClientFight.DataManagerTest:setFormationInfo(decodeJsonStrToTabel(info))

end
return CSharpModel